package rad.framework.mda.generator.template.main.resources;

import java.util.*;
import org.eclipse.uml2.uml.*;
import rad.framework.mda.generator.util.*;

public class BetwixtConfig
{
  protected static String nl;
  public static synchronized BetwixtConfig create(String lineSeparator)
  {
    nl = lineSeparator;
    BetwixtConfig result = new BetwixtConfig();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "<?xml version=\"1.0\"?>" + NL + "<betwixt-config>";
  protected final String TEXT_2 = NL + "\t<class name=\"";
  protected final String TEXT_3 = ".";
  protected final String TEXT_4 = "\">" + NL + "\t\t<element name=\"";
  protected final String TEXT_5 = "\">";
  protected final String TEXT_6 = NL + "\t\t\t<element name=\"";
  protected final String TEXT_7 = "\">" + NL + "\t\t\t\t<element property='";
  protected final String TEXT_8 = "'>" + NL + "\t\t\t\t\t<element property='";
  protected final String TEXT_9 = "'/>" + NL + "\t\t\t\t</element>" + NL + "\t\t\t</element>";
  protected final String TEXT_10 = NL + "\t\t\t<element name=\"";
  protected final String TEXT_11 = "\">" + NL + "\t\t\t\t<element property='";
  protected final String TEXT_12 = "'>" + NL + "\t\t\t\t\t<element property='";
  protected final String TEXT_13 = "'/>" + NL + "\t\t\t\t</element>" + NL + "\t\t\t</element>";
  protected final String TEXT_14 = NL + "\t\t\t<element name=\"";
  protected final String TEXT_15 = "\">" + NL + "\t\t\t\t<element property='";
  protected final String TEXT_16 = "' updater='add";
  protected final String TEXT_17 = "'>" + NL + "\t\t\t\t\t<element property='";
  protected final String TEXT_18 = "' updater='add";
  protected final String TEXT_19 = "'/>" + NL + "\t\t\t\t</element>" + NL + "\t\t\t</element>";
  protected final String TEXT_20 = NL + "\t\t\t<element name=\"";
  protected final String TEXT_21 = "\">" + NL + "\t\t\t\t<element property='";
  protected final String TEXT_22 = "' updater='add";
  protected final String TEXT_23 = "'>" + NL + "\t\t\t\t\t<element property='";
  protected final String TEXT_24 = "' updater='add";
  protected final String TEXT_25 = "'/>" + NL + "\t\t\t\t</element>" + NL + "\t\t\t</element>";
  protected final String TEXT_26 = NL + "\t\t\t<addDefaults/>" + NL + "\t\t</element>" + NL + "\t</class>";
  protected final String TEXT_27 = NL + "</betwixt-config>";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    Model uml2Model = (Model) argument;
    stringBuffer.append(TEXT_1);
    for (Iterator i=ClassHelper.getClasses(uml2Model).iterator(); i.hasNext();) { org.eclipse.uml2.uml.Class element = (org.eclipse.uml2.uml.Class)i.next();
    stringBuffer.append(TEXT_2);
    stringBuffer.append(NameHelper.getQualifiedName(element.getPackage()));
    stringBuffer.append(TEXT_3);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(element.getName());
    stringBuffer.append(TEXT_5);
    for (Iterator<Property> j=ClassHelper.getAllManyToOneProperties(element); j.hasNext();) { Property property = j.next();
    if (ClassHelper.hasSubclasses((org.eclipse.uml2.uml.Class)property.getType()) || element.equals(property.getType())) {
    stringBuffer.append(TEXT_6);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_7);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_9);
    }}
    for (Iterator<Property> j=ClassHelper.getAllOneToOneProperties(element); j.hasNext();) { Property property = j.next();
    if (ClassHelper.hasSubclasses((org.eclipse.uml2.uml.Class)property.getType()) || element.equals(property.getType())) {
    stringBuffer.append(TEXT_10);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_12);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_13);
    }}
    for (Iterator<Property> j=ClassHelper.getAllOneToManyProperties(element); j.hasNext();) { Property property = j.next();
    if (ClassHelper.hasSubclasses((org.eclipse.uml2.uml.Class)property.getType())) {
    stringBuffer.append(TEXT_14);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_15);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_16);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_17);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_18);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_19);
    }}
    for (Iterator<Property> j=ClassHelper.getAllManyToManyProperties(element); j.hasNext();) { Property property = j.next();
    if (ClassHelper.hasSubclasses((org.eclipse.uml2.uml.Class)property.getType())) {
    stringBuffer.append(TEXT_20);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_21);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_22);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_23);
    stringBuffer.append(property.getName());
    stringBuffer.append(TEXT_24);
    stringBuffer.append(ClassHelper.getAccessorNameNonPlural(property));
    stringBuffer.append(TEXT_25);
    }}
    stringBuffer.append(TEXT_26);
    }
    stringBuffer.append(TEXT_27);
    return stringBuffer.toString();
  }
}
